Skip to content

fix(objectql): stamp tenant org-key onto un-pinned business seed rows#2376

Merged
os-zhuang merged 1 commit into
mainfrom
fix/seed-loader-org-fallback
Jun 27, 2026
Merged

fix(objectql): stamp tenant org-key onto un-pinned business seed rows#2376
os-zhuang merged 1 commit into
mainfrom
fix/seed-loader-org-fallback

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Problem

An AI-built app lands empty in every list / kanban even though the seeded rows physically exist in the tenant DB.

Root cause (confirmed live on a built app): a published seed loaded in-process (the build agent's publish path) has no active user session, so config.organizationId is unset and the SQL driver's per-write org injection never fires → business seed rows persist with organization_id = NULL. Under strict org-scoping the data API filters WHERE organization_id = <activeOrg> and a NULL row matches nobody, so reads come back total:0.

Metadata + dashboard datasets read via a system (non-org-scoped) path, so the app shell, views and dashboard counts render — only the business data is invisible. That's the "I built it and it's empty" footgun. (Single-org today it's only latent; the moment the env gains a second org / stricter scope the data disappears — an existing env is the live sample.)

Live evidence

On a freshly-built env, raw table had 12 work orders, all organization_id = NULL; /api/v1/data/... returned total:0. Stamping one row with the env's org made it (and only it) appear; stamping all 12 made the lists + kanban populate.

Fix

When no org is pinned, SeedLoaderService resolves the tenant's sole organization and stamps business seed rows with it — the tenant key a normal create would inject.

  • sys_/cloud_/ai_ platform seeds never take the fallback (stay global/cross-tenant).
  • 0 or >1 orgs → leave rows org-less (genuinely ambiguous → unchanged historical behavior).
  • An explicitly pinned organizationId still wins, for every object (unchanged).
  • Bonus: os.org.id now resolves in seed CEL on the un-pinned path.

Tests

src/seed-loader-org-fallback.test.ts (5): sole-org stamp · sys_ skip · ambiguous no-op · no-org no-op · explicit-org precedence. Existing seed-loader + protocol suites green (12 → no regression). @objectstack/objectql builds clean (DTS incl. deps).

🤖 Generated with Claude Code

…rows

A published seed loaded in-process (the AI build agent's publish path) has
no active user session, so `config.organizationId` is unset and the SQL
driver's per-write org injection never fires — business seed rows land with
`organization_id = NULL`. Under strict org-scoping the data API filters with
`WHERE organization_id = <activeOrg>` (a NULL row matches nobody), so every
list / kanban / read of the freshly-built app comes back empty even though the
rows physically exist. (Metadata + dashboard datasets read via a system,
non-org-scoped path, so the app shell and dashboard counts render — only the
business data vanishes, which reads as "I built it and it's empty".)

Fix: when no org is pinned, the SeedLoader resolves the tenant's SOLE
organization and stamps BUSINESS seed rows with it — the same tenant key a
normal create injects from the session. `sys_`/`cloud_`/`ai_` platform seeds
never take the fallback (they stay intentionally global/cross-tenant); zero or
several orgs leave rows org-less (genuinely ambiguous → unchanged behavior);
an explicitly pinned `organizationId` still wins for every object.

Also makes `os.org.id` resolvable in seed CEL on the un-pinned path (the
fallback flows into the seed identity's `org`).

Tests: src/seed-loader-org-fallback.test.ts — sole-org stamp, sys_ skip,
ambiguous/no-org no-op, explicit-org precedence. Existing seed-loader +
protocol suites green (no regression).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 27, 2026 2:36pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/objectql.

14 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/concepts/core/services.mdx (via @objectstack/objectql)
  • content/docs/concepts/implementation-status.mdx (via @objectstack/objectql)
  • content/docs/concepts/metadata-lifecycle.mdx (via @objectstack/objectql)
  • content/docs/concepts/packages.mdx (via @objectstack/objectql)
  • content/docs/guides/authentication.mdx (via @objectstack/objectql)
  • content/docs/guides/deployment-vercel.mdx (via @objectstack/objectql)
  • content/docs/guides/formula.mdx (via packages/objectql)
  • content/docs/guides/kernel-services.mdx (via @objectstack/objectql)
  • content/docs/guides/objectql-migration.mdx (via @objectstack/objectql)
  • content/docs/guides/packages.mdx (via @objectstack/objectql)
  • content/docs/guides/plugins.mdx (via @objectstack/objectql)
  • content/docs/protocol/objectos/index.mdx (via @objectstack/objectql)
  • content/docs/protocol/objectql/state-machine.mdx (via @objectstack/objectql)
  • content/docs/releases/v9.mdx (via @objectstack/objectql)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

@os-zhuang
os-zhuang merged commit c584e21 into main Jun 27, 2026
16 checks passed
@os-zhuang
os-zhuang deleted the fix/seed-loader-org-fallback branch June 27, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant